package com.sdx.console.system.service;

import java.util.List;

import org.beetl.sql.core.engine.PageQuery;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ibeetl.admin.core.util.PlatformException;

import com.sdx.console.system.dao.PromoteRecordDao;
import com.sdx.console.system.entity.PromoteRecord;
import com.ibeetl.admin.core.service.BaseService;

/**
 * 推广码 Service
 */

@Service
@Transactional
public class PromoteRecordService extends BaseService<PromoteRecord>{

    @Resource
	private PromoteRecordDao promoteRecordDao;

    public PageQuery<PromoteRecord>queryByCondition(PageQuery query){
        PageQuery ret =  promoteRecordDao.queryByCondition(query);
        queryListAfter(ret.getList());
        return ret;
    }

    public void batchDelPromoteRecord(List<String> ids){
        try {
            promoteRecordDao.batchDelPromoteRecordByIds(ids);
        } catch (Exception e) {
            throw new PlatformException("批量删除推广码失败", e);
        }
    }

	public List<PromoteRecord> all() {
		return promoteRecordDao.all();
		}

	public int selectCodeCount(String promoteCode) {
    	PromoteRecord param = new PromoteRecord();
    	param.setPromoteCode(promoteCode);
    	int count = sqlManager.intValue("system.promoteRecord.selectCodeCount",param);
    	return count;
	}

    public List<PromoteRecord> selectRecord(String channelCode,Long orgId) {
        return promoteRecordDao.selectRecord(channelCode,orgId);
    }
}